package com.zxy.Answer.controller;

import com.zxy.Answer.common.BaseResponse;
import com.zxy.Answer.common.ErrorCode;
import com.zxy.Answer.common.ResultUtils;
import com.zxy.Answer.exception.ThrowUtils;
import com.zxy.Answer.mapper.UserAnswerMapper;
import com.zxy.Answer.model.dto.useranswer.UserAnswerCountDTO;
import com.zxy.Answer.model.dto.useranswer.UserAnswerResultNameCountDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * app统计分析接口
 *
 * @author <a href="https://gitee.com/zxyyyds666">落花</a>
 */
@RestController
@RequestMapping("/app/statistic")
@Slf4j
public class StatisticController {
    @Resource
    private UserAnswerMapper userAnswerMapper;

    /**
     * 热门应用统计（top 10）
     * */
    @GetMapping("/answer_count")
    public BaseResponse<List<UserAnswerCountDTO>> getAppAnswerCount() {
        return ResultUtils.success(userAnswerMapper.doAppAnswerCount());
    }

    /**
     * 某应用结果名称统计
     * */
    @GetMapping("/answer_resultName_count")
    public BaseResponse<List<UserAnswerResultNameCountDTO>> getAppAnswerResultNameCount(Long appId) {
        ThrowUtils.throwIf(appId == null || appId <= 0, ErrorCode.PARAMS_ERROR);
        return ResultUtils.success(userAnswerMapper.doAppAnswerResultNameCount(appId));
    }
}
